<!doctype html>
<html>
<head>
    @include("/template/inc/inc.html"){}
    <title>定时任务列表</title>
    <script>
        function getRow(index) {
            $('#dg').datagrid('selectRow', index - 1);
            var row = $('#dg').datagrid('getSelected');
            return row;
        }
        function updateCron(index) {
            var row = getRow(index);
            $.messager.prompt('修改Cron', '请输入Cron表达式', function (r) {
                if (r) {
                    var url = '${ctxPath}/quartz/job/updateCronExpression?triggerGroup={0}&triggerName={1}&cronExpression={2}';
                    url = url.replace('{0}', row.triggerGroup);
                    url = url.replace('{1}', row.triggerName);
                    url = url.replace('{2}', r);
                    location.href = url;
                }
            }).find(':input').val(row.cronExpression);
        }
        function action(index, actionName) {
            var row = getRow(index);
            var title = '';
            var msg = '';
            switch (actionName) {
                case "delete":
                    title = '删除任务';
                    msg = '确定要删除当前任务？';
                    break;
                case "resume":
                    title = '恢复任务';
                    msg = '确定要恢复当前任务？';
                    break;
                case "resumeAll":
                    title = '恢复所有任务';
                    msg = '确定要恢复所有任务？';
                    break;
                case "pause":
                    title = '暂停任务';
                    msg = '确定要暂停当前任务？';
                    break;
                case "pauseAll":
                    title = '暂停所有任务';
                    msg = '确定要暂停所有任务？';
                    break;
                case "trigger":
                    title = '触发任务';
                    msg = '确定要触发当前任务？';
                    break;
            }
            $.messager.confirm(title, msg, function (r) {
                if (r) {
                    var url;
                    if (index > -1) {
                        url = '${ctxPath}/quartz/job/{0}?jobGroup={1}&jobName={2}';
                        url = url.replace('{1}', row.jobGroup);
                        url = url.replace('{2}', row.jobName);
                    } else {
                        url = '${ctxPath}/quartz/job/{0}';
                    }
                    url = url.replace('{0}', actionName);
                    location.href = url;
                }
            });
        }
    </script>
</head>
<body>
<div class="easyui-layout" data-options="fit:true">
    <div data-options="region:'center',title:''">
        <div id="tb">
            <a onclick="action(-1,'pauseAll');" href="javascript:void(0);" class="easyui-linkbutton c2">暂停所有任务</a>
            <a onclick="action(-1,'resumeAll');" href="javascript:void(0);" class="easyui-linkbutton c3">恢复所有任务</a>
        </div>
        <table id="dg" class="easyui-datagrid" title="定时任务列表" data-options="fit:true,fitColumns:true,striped:true,singleSelect:true,toolbar:'#tb'">
            <thead>
            <tr>
                <th data-options="field:'index'">序号</th>
                <th data-options="field:'jobGroup',hidden:true">任务组</th>
                <th data-options="field:'jobName'">任务ID</th>
                <th data-options="field:'triggerName'">触发ID</th>
                <th data-options="field:'triggerGroup',hidden:true">触发组</th>
                <th data-options="field:'startTime'">任务开启时间</th>
                <th data-options="field:'nextFireTime'">下次触发时间</th>
                <th data-options="field:'previousFireTime'">上次触发时间</th>
                <th data-options="field:'cronExpression'">Cron表达式</th>
                <th data-options="field:'triggerState'">状态</th>
                <th data-options="field:'schedulerName',hidden:true">调度名称</th>
                <th data-options="field:'action'">操作</th>
            </tr>
            </thead>
            <tbody>
            @for(job in jobs){
            @if(isNotEmpty(job.cronExpression)){
            <tr>
                <td>${jobLP.index}</td>
                <td>${job.jobGroup}</td>
                <td>${job.jobName}</td>
                <td>${job.triggerName}</td>
                <td>${job.triggerGroup}</td>
                <td>${job.startTime,dateFormat='yyyy-MM-dd HH:mm:ss'}</td>
                <td>${job.nextFireTime,dateFormat='yyyy-MM-dd HH:mm:ss'}</td>
                <td>${job.previousFireTime,dateFormat='yyyy-MM-dd HH:mm:ss'}</td>
                <td>${job.cronExpression}</td>
                <td>${job.triggerState}</td>
                <td>${job.schedulerName}</td>
                <td>
                    <a onclick="updateCron('${jobLP.index}');" href="javascript:void(0);" class="easyui-linkbutton c4">修改Cron</a>
                    <a onclick="action('${jobLP.index}','pause');" href="javascript:void(0);" class="easyui-linkbutton c2">暂停任务</a>
                    <a onclick="action('${jobLP.index}','resume');" href="javascript:void(0);" class="easyui-linkbutton c3">恢复任务</a>
                    <a onclick="action('${jobLP.index}','trigger');" href="javascript:void(0);" class="easyui-linkbutton c1">触发一次</a>
                    <a onclick="action('${jobLP.index}','delete');" href="javascript:void(0);" class="easyui-linkbutton c5">删除任务</a>
                </td>
            </tr>
            @}
            @}
            </tbody>
        </table>
    </div>
</div>
</body>
</html>